/*
 * File:   main.cpp
 * Author: Gab'z
 *
 * Created on 30 avril 2012, 13:05
 */

#include <QtGui/QApplication>
#include "model/Context.h"
#include "controler/Engine.h"
#include "view/CalculatorMainWindow.h"
#include <string>
#include "log/LogSystem.h"
#include "tool/XMLParser.h"

using namespace calculator;
using namespace std;

int main(int argc, char *argv[]) {

    Logger * log = LoggerManager::getInstance()->getLogger("MAIN");

    XMLParser* xmlParser = XMLParser::getInstance();
    // initialize resources, if needed
    // Q_INIT_RESOURCE(resfile);

    // Initialisation de l'application Calculatrice NPI
    // Design pattern MVC
    log->trace("Creating context");
    Context* context = Context::getInstance();
    xmlParser->loadContextFromFile(context, calculator::saveFilename);

    log->trace("Creating engine");
    Engine* engine = new Engine(context);

    log->trace("Creating interface");
    QApplication app(argc, argv);
    CalculatorMainWindow mainWindow;

    log->trace("Setting engine to interface");
    mainWindow.setEngine(engine);

    log->trace("Initialization interface");
    mainWindow.init();

    log->trace("Show interface");
    mainWindow.show();




    app.exec();



    mainWindow.prepareForShutdown();
    if (context->getParameters()->getSaveOnExit()) xmlParser->saveContextToFile(context, calculator::saveFilename);
    ;
    delete engine;
    Context::deleteInstance();




    log->debug("fin main");
    LoggerManager::deleteInstance();
    return 0;
}
